package com.moorror.codegenvel.common.actions.toolbaractions;

import com.intellij.icons.AllIcons;
import com.intellij.openapi.actionSystem.AnAction;
import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.ui.tabs.TabInfo;
import com.moorror.codegenvel.view.component.AbstractCodeGenByVelocitySetTab;
import com.moorror.codegenvel.view.component.CodeGenByVelocityTabBar;

import javax.swing.*;


/**
 * @Author jiyanghuang
 * @Date 2022/8/7 13:50
 */
public class CloseTabAction extends AnAction {
    private AbstractCodeGenByVelocitySetTab abstractToolSetTab;

    public CloseTabAction(AbstractCodeGenByVelocitySetTab abstractToolSetTab) {
        super("Close Tab", "Close selected Tab", AllIcons.Actions.Close);
        this.abstractToolSetTab = abstractToolSetTab;
    }

    @Override
    public void actionPerformed(AnActionEvent anActionEvent) {
        SwingUtilities.invokeLater(() -> {
            CodeGenByVelocityTabBar sequenceOutlineTabBar = abstractToolSetTab.getToolSetTabBar();
            TabInfo tabInfoSelect = sequenceOutlineTabBar.getSelectedInfo();
            if(null != tabInfoSelect){
                sequenceOutlineTabBar.removeTab(tabInfoSelect);
            }
        });
    }
}
